<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/vue.js"></script>
    <style>
        li {
            list-style: none;
        }
    </style>
</head>

<body>
    <div id="root">
        <h2>学校{{name}}</h2>
        <h2>地址:{{address}}</h2>
        <hr>
        <h1>学生信息</h1>
        <button @click="addsex">添加一个性别，默认男</button>
        <h2>学生姓名{{student.name}}</h2>
        <h2 v-if="student.sex">性别{{student.sex}}</h2>
        <h2>学生年龄：{{student.age.rage}} amd {{student.age.sage}}</h2>
        <h2>朋友们</h2>

        <ul>
            <li v-for="(f,index) in student.friends" :key="index">  
                  {{f.name}} - {{f.age}}</li>
        </ul>
        <h2>爱好</h2>

        <ul>
            <li v-for="(h,index) in student.hobby" :key="index">  
                  {{h}} </li>
        </ul>
    
        
    </div>

    <script>

        // 用computed实现
         const vm = new Vue({
            el: '#root',
            data: {
             name:'越',
             address:'湖北',
             student:{
                 name:'xiba',
                 sex:'',
                 age:{
                     rage:'40',
                     sage:'18',

                 },
                 hobby:['吃瓜','看书','睡觉'],
                 friends:[
                     {name:'goudan',age:'19'},
                     {name:'ssb',age:'29'}
                 ]
             }
            },
            methods: {
                addsex(){
                    Vue.set(this.student,'sex','男')
                }
            },
        

        })
    </script>
</body>

</html>